What is lodash.pickby?
The lodash.pickby npm package is a method from the Lodash library that creates an object composed of the object properties predicate returns truthy for. The predicate is invoked with two arguments: (value, key).
What are lodash.pickby's main functionalities?
Filtering object properties based on values
This code uses lodash.pickby to create a new object from the given object by keeping only the properties where the values are numbers.
{"result": _.pickBy({ 'a': 1, 'b': '2', 'c': 3 }, _.isNumber)}
Filtering object properties based on custom predicate
This code demonstrates how to use a custom predicate function to filter object properties, keeping only those where the value is greater than 1.
{"result": _.pickBy({ 'a': 1, 'b': '2', 'c': 3 }, function(value) { return value > 1; })}
Other packages similar to lodash.pickby
object.pick
The object.pick package is similar to lodash.pickby in that it allows you to create a new object by picking properties from an existing object. However, object.pick does not support predicate functions; it only allows picking based on an array of property names.
just-pick
Just-pick is another package that provides functionality similar to lodash.pickby, allowing you to pick properties from an object. Like object.pick, it does not support predicate functions and requires an array of property names to determine which properties to include in the new object.
lodash.pickby v4.6.0
The lodash method _.pickBy
exported as a Node.js module.
Installation
Using npm:
$ {sudo -H} npm i -g npm
$ npm i --save lodash.pickby
In Node.js:
var pickBy = require('lodash.pickby');
See the documentation or package source for more details.